#include <iostream>

using namespace std;

void swap(int * a, int * b) 
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

void bubbleSort(int * arr, int len)
{
    bool flag;
    for (int i = 0; i < len - 1; i++)
    {
        flag = false;
        for (int j = 0; j < len - 1 - i; j++)
        {
            if (arr[j] > arr[j + 1])
            {
                swap(&arr[j], &arr[j + 1]);
                flag = true;
            }
        }
        if (!flag)
        {
            break;
        }
    }
}

void printArray(int * arr, int len)
{
    for (int i = 0; i < len; i++)
    {
        cout << arr[i] << " ";
    }
}

int main()
{
    int a = 10;
    int b = 20;

    cout << "a = " << a << endl;
    cout << "b = " << b << endl;

    swap(&a, &b);

    cout << "a = " << a << endl;
    cout << "b = " << b << endl;

    int arr[10] = { 4, 3, 6, 9, 1, 2, 10, 8, 7, 5 };

    int len = sizeof(arr) / sizeof(arr[0]);
    bubbleSort(arr, len);
    printArray(arr, len);

    //int a = rand();

    system("pause");

    return 0;

}